<template>
	<view class="box">
		<view class="header">
			<view class="left" @click="go">
				<image src="https://s1.ax1x.com/2022/12/02/zBZYkQ.jpg" mode=""></image>
				返回
			</view>
			<view class="center">
				生活缴费
			</view>
		</view>
		<view class="top">
			<view class="left" @click="all">
				全部
			</view>
			<view class="type">
				<picker :range="feetype" :range-key="'name'" @change="getfeeName">
					<view>
						{{ !feetypeName ? '请选择缴费类型' :  feetypeName}}
						<image src="https://s1.ax1x.com/2022/12/02/zDC3QS.png" mode=""></image>
					</view>
				</picker>
			</view>
		</view>
		<view class="cell">
			<picker :range="buildingName" :range-key="'building'" @change="getfeeList">
				<view class="left">
					{{building}}
					<image src="https://s1.ax1x.com/2022/12/02/zDCsL4.png" mode=""></image>
				</view>
			</picker>
			<!-- <text>2021-09<text class="iconfont icon-xiangxia1" ></text></text> -->
			<picker mode="date" @change="changeDate" fields="day">
				<view class="right">{{day}}
					<image src="https://s1.ax1x.com/2022/12/02/zDC3QS.png" mode=""></image>
				</view>
			</picker>
		</view>
		<view class="list" v-for="(item,index) in feelist" :key="index">
			<view class="title">
				<text>{{item.type}}</text>
			</view>
			<view class="ul">
				<view class="li">
					<div class="label">
						房号
					</div>
					<div class="content">
						{{item.houseno}}
					</div>
				</view>
				<view class="li">
					<div class="label">
						账单
					</div>
					<div class="content">
						{{item.begindate}}至{{item.enddate}}
					</div>
				</view>
				<view class="li">
					<div class="label">
						账单金额
					</div>
					<div class="content">
						{{item.price}}
					</div>
				</view>
				<view class="li">
					<div class="label">
						缴费时间
					</div>
					<div class="content">
						{{item.addtime}}
					</div>
				</view>
				<view class="li">
					<div class="label">
						付款方式
					</div>
					<div class="content">
						微信支付
					</div>
				</view>
			</view>
		</view>
		<view class="btm">

		</view>
	</view>
</template>

<script>
	import {
		feelist,
		feetypelist,
		houseCheck
	} from "pages/utils/api.js"
	export default {
		data() {
			return {
				searchData: {
					houseno: '', // 房间id
					begindate: '',
					enddate: '',
					type: '', // 默认为空代表查询全部
					page: 1,
					psize: 5
				},
				feelist: [],
				buildlist: [],
				feetype: [],
				buildingName:[],
				building:'请选择房间',
				feetypeName: '请选择缴费',
				day: '请选择月份', //月份
				houselist:[]
			}
		},
		async onLoad() {
			this.getfeetypelist()
			await this.getfeelist()
			this.gethouseCheck()

		},
		methods: {
			async gethouseCheck() {
				let res = await houseCheck()
				console.log(res);
				if (res.errCode == 10000) {
					res.data.list.map(item => {
						this.buildingName = [...this.buildingName, item.building]
					})
					this.houselist = res.data.list
				}
			},
			all() {
				this.searchData.page = 1
				// this.searchData.type=''
				// this.feetypeName=''
				this.getfeelist()
			},
			async getfeetypelist() {
				let res = await feetypelist()
				console.log(res);
				if (res.errCode == 10000) {
					this.feetype = res.data.list
				}
			},
			async getfeelist() {
				let res = await feelist({
					begindate: this.searchData.enddate,
					type: this.searchData.type
				})
				this.feelist = res.data.list
			},
			getfeeName(e) {
				console.log(e);
				this.feetypeName = this.feetype[e.detail.value].name
				this.searchData.type = this.feetype[e.detail.value].name
				// this.feelist = []
				this.getfeelist(this.feetype[e.detail.value].name)
			},
			getfeeList(e) {
				this.building = this.houselist[e.detail.value].building
				this.houseno = this.feelist[e.detail.value].houseid

			},
			// 切换日期
			changeDate(e) {
				console.log(e);
				if (e) {
					this.day = e.detail.value
				}
				this.searchData.page = 1
				this.searchData.type = ''
				this.searchData.begindate = this.day + '-01'
				this.searchData.enddate = this.$moment(this.day).endOf('day').format('YYYY-MM-DD')
				console.log(this.searchData.enddate);
				this.getlist(this.searchData.enddate)
			},
			go() {
				uni.navigateBack({
					delta: 1
				})
			}
		}

	}
</script>

<style lang="less">
	.box {
		width: 100%;
		background-color: #f0f0f0;

		.header {
			width: 730rpx;
			height: 135rpx;
			background-color: #fff;
			display: flex;
			align-items: center;
			padding: 0 10rpx;
			font-size: 26rpx;

			.left {
				display: flex;

				image {
					width: 26rpx;
					height: 25rpx;
					display: block;
					margin-top: 6rpx;
				}

			}

			.center {
				margin-left: 230rpx;
			}
		}

		.top {
			width: 730rpx;
			height: 80rpx;
			background-color: #fff;
			display: flex;
			justify-content: space-between;
			padding: 0 10rpx;
			font-size: 28rpx;

			.left {
				color: #0080fe;

			}

			.type {
				image {
					margin: 0 10rpx;
					width: 28rpx;
					height: 17rpx;
				}
			}
		}

		.cell {
			width: 730rpx;
			height: 100rpx;
			padding: 0 10rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;

			.left {
				margin-left: 30rpx;
				font-size: 28rpx;

				image {
					width: 35rpx;
					height: 18rpx;
					margin-left: 10rpx;
				}

			}

			.right {
				display: flex;

				image {
					margin: 0 10rpx;
					width: 28rpx;
					height: 17rpx;
					margin-top: 10rpx;
				}
			}
		}

		.list {
			width: 720rpx;
			height: 428rpx;
			margin: 20rpx auto;
			border-radius: 20rpx;
			background-color: #fff;

			.title {
				margin: 30rpx;
				padding: 20rpx;
				border-bottom: 1rpx solid #eeeeee
			}

			.ul {
				margin: 20rpx;

				.li {
					display: flex;
					justify-content: space-between;
					padding: 10rpx;
				}
			}
		}

		.btm {
			width: 100%;
			height: 200rpx;
		}
	}
</style>
